package com.example.child_protection.controller;

import com.example.child_protection.dto.base.BaseResponseDTO;
import com.example.child_protection.dto.request.SimpleIdRequestDTO;
import com.example.child_protection.dto.request.add.AssessInsertRequestDTO;
import com.example.child_protection.dto.request.find.AssessRequestDTO;
import com.example.child_protection.dto.request.update.AssessUpdateRequestDTO;
import com.example.child_protection.dto.response.AssessListResponseDTO;
import com.example.child_protection.dto.response.AssessResponseDTO;
import com.example.child_protection.service.AssessManageService;
import com.example.child_protection.service.AssessQueryService;
import com.example.child_protection.util.ContentType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 高危管理控制层
 * @date 2018-11-2
 * @author Biz
 */
@RestController
@RequestMapping("assess")
@Api(value = "/api-assess", description = "高危管理")
public class AssessController extends BaseController {

    @Autowired
    public AssessManageService assessManageService;

    @Autowired
    public AssessQueryService assessQueryService;

    @ApiOperation(value ="查询高危", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/findId", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public AssessResponseDTO findId(SimpleIdRequestDTO requestDTO,HttpServletRequest request)throws Exception{
        AssessResponseDTO responseDTO = assessQueryService.findId(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="查询高危列表信息", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/findList", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public AssessListResponseDTO findList(AssessRequestDTO requestDTO, HttpServletRequest request)throws Exception{
        AssessListResponseDTO responseDTO = assessQueryService.findList(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="添加高危", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/insert", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO insert(AssessInsertRequestDTO requestDTO)throws Exception{
        requestDTO.setCreatePersonId(this.getLoginUserId());
        requestDTO.setLastUpdatePersonId(this.getLoginUserId());
        BaseResponseDTO responseDTO = assessManageService.insert(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="修改高危", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/update", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO update(AssessUpdateRequestDTO requestDTO)throws Exception{
        requestDTO.setLastUpdatePersonId(this.getLoginUserId());
        BaseResponseDTO responseDTO = assessManageService.update(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="删除高危", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/delete", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO delete(SimpleIdRequestDTO requestDTO)throws Exception{
        requestDTO.setLastUpdatePersonId(this.getLoginUserId());
        BaseResponseDTO responseDTO = assessManageService.delete(requestDTO);
        return responseDTO;
    }

}
